﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Presentation_Layer.WcfFlightRoutingService;
using System.Collections.ObjectModel;

namespace Presentation_Layer
{
    /// <summary>
    /// Interaction logic for ListViewImp.xaml
    /// </summary>
    public partial class ListViewImp : Window
    {
        private WcfFlightRoutingService.IService wcfService;
        public ObservableCollection<string> fileList = new ObservableCollection<string>();
        


        public ListViewImp()
        {
            InitializeComponent();
            wcfService = new WcfFlightRoutingService.ServiceClient();
            
        }
        

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            //DataTable dt = (DataTable)flightListView.DataContext;
            //if (!dt.Rows[0][1].ToString().Equals("") && flightListView.SelectedIndex >= 0)
            //{
            //    var window = new ShowSelectedFlight();
            //    window.Show();
            //}
        }

        private void FlightListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {

           


            //try
            //{
            //    List<Flight> flightList = wcfService.GetAllFlights(true);

            //    //List<object> myNewList = new List<object>(flightArray);
            //    //if (myNewList != null)
            //    if (flightList != null)
            //    {
            //        //foreach (Flight flight in myNewList)                
            //        foreach (Flight flight in flightList)
            //        {
            //            ListViewItem listViewItem = new ListViewItem(flight.Idflight.ToString());
            //            listViewItem.SubItems.Add(flight.Objairplane.Idairplane.ToString());
            //            listViewItem.SubItems.Add(flight.Traveltime.ToString());
            //            listViewItem.SubItems.Add(flight.Timeofdeparture);
            //            listViewItem.SubItems.Add(flight.Timeofarrival);
            //            listViewItem.SubItems.Add(flight.Availableseats.ToString());
            //            listViewItem.SubItems.Add(flight.Takenseats.ToString());
            //            listViewItem.SubItems.Add(flight.Price.ToString());
            //            listViewItem.SubItems.Add(flight.StartAirport.Name.ToString());
            //            listViewItem.SubItems.Add(flight.DestinationAirport.Name.ToString());
            //            listViewObj.Items.Add(listViewItem);
            //        }
            //    }
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show(ex.Message);
            //}
        }

         private void flightListView_SelectionChanged(object sender, SelectionChangedEventArgs e)
         {
             try
             {

                 List<Flight> flightList = wcfService.GetAllFlights(true);

                 flightListView.Items.Add("Flight ID");
                 flightListView.Items.Add("Departure");
                 flightListView.Items.Add("Destination");
                 flightListView.Items.Add("Price");
                 flightListView.Items.Add("Time of departure");
                 flightListView.Items.Add("Time of arrival");
                 flightListView.Items.Add("Travel time");
                 flightListView.Items.Add("Taken seats");
                 flightListView.Items.Add("Airplane ID");
                 List<Flight> list = wcfService.GetAllFlights(true);
                 //foreach (Flight flight in flightList)
                 //{
                 //    flightListView.Items.Add(flight.Idflight.ToString(), flight.StartAirport.Name, flight.DestinationAirport.Name, flight.Price.ToString(),
                 //        String.Format("{0:d/MM/yyyy HH:mm}", flight.Timeofarrival),
                 //        String.Format("{0:d/MM/yyyy HH:mm}", flight.Timeofdeparture), flight.Traveltime.ToString(),
                 //        flight.Takenseats.ToString(), flight.Objairplane.Idairplane.ToString());
                 //}
                 flightListView.DataContext = flightListView;
             }
             catch (Exception ex)
             {
                 throw new Exception(ex.Message);
             }
         }

         //public ObservableCollection<string> FileStore
         //{

         //    get { return flightList;  }
         //} 
    }
}
